<template>
  <el-dialog :title="title" :visible.sync="dialogAddNew" width="50%" center>
    <el-form ref="storehouseForm" :model="storehouseForm" :rules="rules">
      <el-form-item label="仓库编号" :label-width="formLabelWidth" prop="warehouseId">
        <el-select v-model="storehouseForm.warehouseId" placeholder="请选择库位编号">
          <el-option
            v-for="item in warehouseInfoList"
            :key="item.warehouseId"
            :label="item.warehouseId"
            :value="item.warehouseId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="库位编号" :label-width="formLabelWidth" prop="storehouseId">
        <el-input v-model="storehouseForm.storehouseId" autocomplete="off" />
      </el-form-item>
      <el-form-item label="名称描述" :label-width="formLabelWidth">
        <el-input v-model="storehouseForm.desc" autocomplete="off" />
      </el-form-item>
      <el-form-item label="库存能力" :label-width="formLabelWidth">
        <el-input v-model="storehouseForm.inventory" autocomplete="off" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogAddNew = false">取 消</el-button>
      <el-button type="primary" @click="addFun('storehouseForm')">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { getWarehouseInfo } from '@/api/wms'
export default {
  props: {
    title: {
      type: String,
      default: '新增'
    }
  },
  data() {
    return {
      dialogAddNew: false,
      formLabelWidth: '80px',
      warehouseInfoList: [],
      storehouseForm: {
        warehouseId: '',
        storehouseId: '',
        desc: '',
        inventory: ''
      },
      rules: {
        warehouseId: [
          { required: true, message: '请选择活动区域', trigger: 'change' }
        ],
        storehouseId: [
          { required: true, message: '请填写库位编号', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getWarehouseInfoList()
  },
  methods: {
    addFun(formName) {
      console.log('添加')
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!')
          console.log(this.warehouseVal)
        } else {
          console.log('error submit!!')
          console.log(this.storehouseForm.warehouseId)
          return false
        }
      })
    },
    getWarehouseInfoList() {
      getWarehouseInfo().then(res => {
        console.log(res)
        this.warehouseInfoList = res.data.items
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
